<?php


namespace Packages\Image\Services;

use App\Tools\Common;
use Jenssegers\ImageHash\ImageHash;
use Jenssegers\ImageHash\Implementations\DifferenceHash;

class ImageService
{

    /**
     * 图片对比
     * @param string $img1 图片地址
     * @param string $img2 图片地址
     * @return int
     */
    public function imgDistance($img1, $img2)
    {
        $hasher = new ImageHash(new DifferenceHash());

        $hash1 = $hasher->hash(Common::urlencode($img1));
        $hash2 = $hasher->hash(Common::urlencode($img2));

        return $hasher->distance($hash1, $hash2);
    }
}
